//
//  overlayView.m
//  hoverNotification
//
//  Created by Daniel Hazelbaker on 1/20/06.
//  Copyright 2006 Blue Box Moon. All rights reserved.
//

#import "overlayView.h"


@implementation overlayView


- (void)drawRect:(NSRect)rect
{
    NSBezierPath    *path;
    NSRect	    frame = [self frame];
    NSPoint	    topLeft, topRight, rightTop, rightBottom, bottomRight, bottomLeft, leftBottom, leftTop;
    unsigned int    CURVE_SIZE = 16;


    //
    // Make sure we don't draw incorrectly if we are too small.
    //
    if ([self frame].size.width < CURVE_SIZE)
	CURVE_SIZE = [self frame].size.width;
    if ([self frame].size.height < CURVE_SIZE)
	CURVE_SIZE = [self frame].size.height;

    //
    // Setup the points we are going to draw between.
    //
    topLeft = NSMakePoint(frame.origin.x + CURVE_SIZE, frame.origin.y + frame.size.height);
    topRight = NSMakePoint(frame.origin.x + frame.size.width - CURVE_SIZE, frame.origin.y + frame.size.height);
    rightTop = NSMakePoint(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height - CURVE_SIZE);
    rightBottom = NSMakePoint(frame.origin.x + frame.size.width, frame.origin.y + CURVE_SIZE);
    bottomRight = NSMakePoint(frame.origin.x + frame.size.width - CURVE_SIZE, frame.origin.y);
    bottomLeft = NSMakePoint(frame.origin.x + CURVE_SIZE, frame.origin.y);
    leftBottom = NSMakePoint(frame.origin.x, frame.origin.y + CURVE_SIZE);
    leftTop = NSMakePoint(frame.origin.x, frame.origin.y + frame.size.height - CURVE_SIZE);

    //
    // Create the path with those points.
    //
    path = [NSBezierPath bezierPath];
    [path moveToPoint:topLeft];

    //
    // Path for top line and top right corner
    //
    [path lineToPoint:topRight];
    [path curveToPoint:rightTop
		controlPoint1:NSMakePoint(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)
		controlPoint2:NSMakePoint(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)];

    //
    // Path for right line and bottom right corner
    //
    [path lineToPoint:rightBottom];
    [path curveToPoint:bottomRight
		controlPoint1:NSMakePoint(frame.origin.x + frame.size.width, frame.origin.y)
		controlPoint2:NSMakePoint(frame.origin.x + frame.size.width, frame.origin.y)];

    //
    // Path for bottom line and bottom left corner
    //
    [path lineToPoint:bottomLeft];
    [path curveToPoint:leftBottom
		controlPoint1:NSMakePoint(frame.origin.x, frame.origin.y)
		controlPoint2:NSMakePoint(frame.origin.x, frame.origin.y)];

    //
    // Path for left line and top left corner
    //
    [path lineToPoint:leftTop];
    [path curveToPoint:topLeft
		controlPoint1:NSMakePoint(frame.origin.x, frame.origin.y + frame.size.height)
		controlPoint2:NSMakePoint(frame.origin.x, frame.origin.y + frame.size.height)];

    //
    // Fill the path with the given color information.
    //
    if (backgroundColor == nil)
	backgroundColor = [[NSColor colorWithCalibratedWhite:0.7f alpha:0.7f] retain];
    [backgroundColor set];
    [path fill];
}

@end
